﻿using System;
using System.Diagnostics;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace EbbinghausWord.Common
{
    /// <summary>
    /// 方法执行时间计数器
    /// </summary>
    public class ExecuteTimer
    {
        private readonly Stopwatch _stopwatch = new Stopwatch();
        private int _counter;
        private bool _isOpen;


        public ExecuteTimer(bool isOpen)
        {
            if (isOpen)
            {
                _stopwatch.Start();
                _counter = 0;
            }
            _isOpen = isOpen;
        }

        /// <summary>
        /// 显示执行时间
        /// </summary>
        /// <param name="message"></param>
        public void Show(string message)
        {
            if (!_isOpen) return;

            _stopwatch.Stop();
            Debug.WriteLine(string.Format("                {0} #{1} {3} ms:{2} ",
                new StackFrame(1).GetMethod().Name, ++_counter, _stopwatch.ElapsedMilliseconds, message));

            _stopwatch.Reset();
            _stopwatch.Start();
        }


        /// <summary>
        /// 显示执行时间
        /// </summary>
        public void Show()
        {
            if (!_isOpen) return;

            _stopwatch.Stop();
            Debug.WriteLine(string.Format("                {0} #{1} ms:{2}",
                new StackFrame(1).GetMethod().Name, ++_counter, _stopwatch.ElapsedMilliseconds));

            _stopwatch.Reset();
            _stopwatch.Start();
        }
    }
}
